<h1><?php echo __('Tagger'); ?></h1>

<div id="snippets-def" class="index-def">
  <div class="snippet"><?php echo __('Tags'); ?> <!-- (<a href="#" onclick="$$('.handle').each(function(e) { e.style.display = e.style.display != 'inline' ? 'inline': 'none'; }); return false;"><?php echo __('reorder'); ?></a>)--></div>
</div>

<ul id="snippets" class="index">
<?php foreach($tags as $tag): ?>
  <li id="snippet_<?php echo $tag->id; ?>" class="snippet node <?php echo odd_even(); ?>">
    <img align="middle" alt="snippet-icon" src="../frog/plugins/tagger/images/tag.png" />
    <a href="<?php echo get_url('plugin/tagger/edit/'.$tag->id); ?>"><?php echo $tag->name; ?>  (<?php echo $tag->count; ?>)</a>
    <?php
    $tagCount = count(TaggerTag::findTagsAndPageAssigned($tag->id));
    if($tagCount > 0): $n = 0; ?>
    <ul class="tagged">
      <?php echo __('tagged:'); ?>
      <?php foreach(TaggerTag::findTagsAndPageAssigned($tag->id) as $url => $title): $n++ ?>
      <li><a href="<?php echo get_url('page/edit/'.$url); ?>"><?php echo $title; ?></a><?php if($tagCount != 1 && $n != $tagCount) echo '&sbquo; '; ?></li>
      <?php endforeach; ?>
    </ul>
    <?php endif; ?>
    <img class="handle" src="images/drag.gif" alt="<?php echo __('Drag and Drop'); ?>" align="middle" />
    <div class="remove"><a href="<?php echo get_url('plugin/tagger/delete/'.$tag->id); ?>" onclick="return confirm('<?php echo __('Are you sure you wish to delete'); ?> <?php echo $tag->name; ?>?');"><img src="images/icon-remove.gif" alt="remove icon" /></a></div>
  </li>
<?php endforeach; ?>
</ul>

<script type="text/javascript" language="javascript" charset="utf-8">
Sortable.create('snippets', {
    constraint: 'vertical',
    scroll: window,
    handle: 'handle',
    onUpdate: function() {
        new Ajax.Request('index.php?/snippet/reorder', {method: 'post', parameters: {data: Sortable.serialize('snippets')}});
    }
});
</script>
